package com.hong.service;

import com.hong.dao.UserDao;
import com.hong.pojo.User;
import com.hong.uitls.JedisUtil;
import com.hong.uitls.SqlSessionUtil;
import org.apache.ibatis.session.SqlSession;
import redis.clients.jedis.Jedis;

import java.util.List;

/**
 * @author user
 */
public class UserService {


    public String getUser(){

        Jedis resource = JedisUtil.getResource();
        String list = resource.get("list");
        if(list==null){
            SqlSession session = SqlSessionUtil.getSession();
            UserDao userDao = session.getMapper(UserDao.class);
            List<User> all = userDao.findAll();
            list= all.toString();

            resource.set("list",list);
            System.out.println("从mysql获取");
        }else {
            System.out.println("从redis获取");
        }
        resource.close();
        return list;
    }
}
